/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.rs.manager.impl;

import java.util.Collection;
import java.util.List;

//import com.xy.biz.dd.client.DataTemplateClient;
//import com.xy.biz.dd.domain.req.SaveDataTemplateRequest;
//import com.xy.biz.dd.domain.resp.GetDataTemplateResponse;
import com.xy.biz.rs.domain.po.ManufactureRecordTemplatePO;
import com.xy.lang.domain.Result;
import com.xy.lang.exception.IncorrectAffectedRowsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.rs.domain.bo.ManufactureRecordTemplateBO;
import com.xy.biz.rs.domain.query.ManufactureRecordTemplateQuery;
import com.xy.biz.rs.domain.converter.ManufactureRecordTemplateConverter;
import com.xy.biz.rs.manager.ManufactureRecordTemplateManager;
import com.xy.biz.rs.dao.ManufactureRecordTemplateDao;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 *
 * @author zsp
 * @date 2021-4-13
 */
@Service
public class ManufactureRecordTemplateManagerImpl implements ManufactureRecordTemplateManager {

	@Autowired
	private ManufactureRecordTemplateDao manufactureRecordTemplateDao;
//	@Autowired
//	private DataTemplateClient dataTemplateClient;

//	@Transactional
//	@Override
//	public ManufactureRecordTemplateBO saveManufactureRecordTemplate(ManufactureRecordTemplateBO manufactureRecordTemplateBO) {
//		if (manufactureRecordTemplateBO.getType() == 1) {
//			ManufactureRecordTemplatePO manufactureRecordTemplatePO = ManufactureRecordTemplateConverter.toPO(manufactureRecordTemplateBO);
//			int row = manufactureRecordTemplateDao.saveManufactureRecordTemplate(manufactureRecordTemplatePO);
//			if (row > 0) {
//				return ManufactureRecordTemplateConverter.toBO(manufactureRecordTemplatePO);
//			}
//		}
//		else{
//			// 添加文件模板
//			SaveDataTemplateRequest saveDataTemplateRequest = SaveDataTemplateRequest.builder()
//					.name(manufactureRecordTemplateBO.getDataTemplateName())
//					.build();
//			Result<GetDataTemplateResponse> result = dataTemplateClient.saveDataTemplate(saveDataTemplateRequest);
//			if(result.wasSuccess()) {
//				manufactureRecordTemplateBO.setDataTemplateId(result.getData().getDataTemplateId());
//				ManufactureRecordTemplatePO manufactureRecordTemplatePO = ManufactureRecordTemplateConverter.toPO(manufactureRecordTemplateBO);
//				int rows = manufactureRecordTemplateDao.saveManufactureRecordTemplate(manufactureRecordTemplatePO);
//				manufactureRecordTemplateBO = ManufactureRecordTemplateConverter.toBO(manufactureRecordTemplatePO);
//				if (rows > 0) {
//					return manufactureRecordTemplateBO;
//				}
//				return null;
//			}
//		}
//		throw new IncorrectAffectedRowsException();
//	}

	@Override
	public int updateManufactureRecordTemplate(ManufactureRecordTemplateBO manufactureRecordTemplateBO) {
		return manufactureRecordTemplateDao.updateManufactureRecordTemplate(ManufactureRecordTemplateConverter.toPO(manufactureRecordTemplateBO));
	}

	@Override
	public int deleteManufactureRecordTemplate(Long manufactureRecordTemplateId) {
		return manufactureRecordTemplateDao.deleteManufactureRecordTemplate(manufactureRecordTemplateId);
	}

	@Override
	public ManufactureRecordTemplateBO getManufactureRecordTemplate(Long manufactureRecordTemplateId) {
		return ManufactureRecordTemplateConverter.fromPO(manufactureRecordTemplateDao.getManufactureRecordTemplate(manufactureRecordTemplateId));
	}

	@Override
	public List<ManufactureRecordTemplateBO> listManufactureRecordTemplateById(Collection<Long> collection) {
		return ManufactureRecordTemplateConverter.fromPO(manufactureRecordTemplateDao.listManufactureRecordTemplateById(collection));
	}

	@Override
	public List<ManufactureRecordTemplateBO> listManufactureRecordTemplate(ManufactureRecordTemplateQuery query) {
		return ManufactureRecordTemplateConverter.fromPO(manufactureRecordTemplateDao.listManufactureRecordTemplate(query));
	}

	@Override
	public int countManufactureRecordTemplate(ManufactureRecordTemplateQuery query) {
		return manufactureRecordTemplateDao.countManufactureRecordTemplate(query);
	}

}
